import 'package:elevator/db/error_data.dart';
import 'package:elevator/model/build_info.dart';
import 'package:elevator/pages/home/all/detail_new/pages/errors/operate/operate_view.dart';
import 'package:flutter/material.dart';
import 'package:flutter_expandable_table/flutter_expandable_table.dart';
import 'package:get/get.dart';

import '../../../../../../../../model/lift_info.dart';
import 'second_logic.dart';

class SecondPage extends StatefulWidget {

  BuildInfo buildInfo;
  LiftInfo liftInfo;

  SecondPage( this.buildInfo, this.liftInfo, {Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _SecondPageState(buildInfo,liftInfo);
  }

}

class _SecondPageState extends State<StatefulWidget>{
  late SecondLogic logic;

  _SecondPageState(BuildInfo buildInfo, LiftInfo liftInfo){
    Get.delete<SecondLogic>();
    logic = Get.put(SecondLogic(buildInfo,liftInfo));
  }

  @override
  Widget build(BuildContext context) {
    return Padding(padding: const EdgeInsets.all(10),
      child: Container(
          width: MediaQuery.of(context).size.width,
          color: Colors.white,
          child: Obx(() { return DataTable(
              headingRowColor:MaterialStateProperty.resolveWith(
                      (states) => Colors.teal
              ),
              border: TableBorder.all(width: 1, color: Colors.grey),
              columns: const [
                DataColumn(
                    numeric: false,
                    tooltip: '2',
                    label: Text('S-NAME')),
                DataColumn(
                  numeric: false,
                  tooltip: '2',
                  label:Text('Value'),
                )
              ],
              rows: [
                DataRow(cells: [
                  const DataCell(Text("PUS Error")),
                  DataCell(Text(logic.pus.value))
                ],),
                DataRow(cells: [
                  const DataCell(Text("PUM Error")),
                  DataCell(Text(logic.puw.value)),
                ]
                ),
                DataRow(cells: [
                  const DataCell(Text("DLS signal counts")),
                  DataCell(Text(logic.dls.value)),
                ]
                ),
                DataRow(cells: [
                  const DataCell(Text("LDS signal counts")),
                  DataCell(Text(logic.lds.value)),
                ]
                ),
                DataRow(cells: [
                  const DataCell(Text("Lift Pulse Data")),
                  DataCell(Text(logic.pulse.value)),
                ]
                )
              ]);})

      ),);
  }

  @override
  void dispose() {
    logic.unregister();
    super.dispose();
  }

  @override
  void initState() {
    logic.register();
    super.initState();
  }
}